import os
from app import create_app, db
from app.models import Admin, User, Department, Menu, Role, RoleMenu, RolePermission
from flask import Flask, send_from_directory
from config import Config

app = create_app(os.getenv('FLASK_CONFIG') or 'default')

@app.shell_context_processor
def make_shell_context():
    """为shell添加上下文"""
    return dict(
        db=db,
        Admin=Admin,
        User=User,
        Department=Department,
        Menu=Menu,
        Role=Role,
        RoleMenu=RoleMenu,
        RolePermission=RolePermission
    )

# 添加静态文件访问路由
@app.route('/uploads/<path:filename>')
def uploaded_file(filename):
    """提供上传文件的访问"""
    return send_from_directory(Config.UPLOAD_FOLDER, filename)

if __name__ == '__main__':
    # 确保上传目录存在
    if not os.path.exists(Config.UPLOAD_FOLDER):
        os.makedirs(Config.UPLOAD_FOLDER, exist_ok=True)
        print(f"创建上传目录: {Config.UPLOAD_FOLDER}")
    
    app.run(host='0.0.0.0', port=5000, debug=True) 